﻿using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace ChivalryUnityEditor
{
    /// <summary>
    /// @Author:Teddy
    /// </summary>
    [CreateAssetMenu(fileName = "SpriteBindData", menuName = "Sprite Bind Data", order = 100)]
    public class SpriteBindData : ScriptableObject
    {
        public List<string> m_bindPath;

        public SpriteBindData()
        {
            m_bindPath = new List<string>();
        }

        /// <summary>
        /// 是否包含路径
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public bool ContainsPath(string path)
        {
            return m_bindPath.Contains(path);
        }

        /// <summary>
        /// 路径序号
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public int IndexOfPath(string path)
        {
            return m_bindPath.IndexOf(path);
        }

        /// <summary>
        /// 替换路径
        /// </summary>
        /// <param name="index"></param>
        /// <param name="newPath"></param>
        public void RepacePath(int index, string newPath)
        {
            if (index >= 0 &&
                index < m_bindPath.Count)
            {
                m_bindPath[index] = newPath;
                EditorUtility.SetDirty(this);
            }
        }

        /// <summary>
        /// 添加路径
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public bool AddPath(string path)
        {
            if (ContainsPath(path))
                return false;

            m_bindPath.Add(path);
            EditorUtility.SetDirty(this);
            return true;
        }

        /// <summary>
        /// 移除路径
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public bool RemovePath(string path)
        {
            bool ret = m_bindPath.Remove(path);
            EditorUtility.SetDirty(this);
            return ret;
        }
    }
}